<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<? error_reporting(0); ?>
<?php
if (isset($_POST['dangnhap'])) {
    $u = $p = "";
    $err = "";
    if ($_POST['tendangnhap'] == NULL || $_POST['matkhau'] == NULL) {
        $err = "Ten dang nhap hoac mat khau khong duoc trong<br />";
    } else {
        $u = $_POST['tendangnhap'];
        $p = $_POST['matkhau'];
    }
}
if ($u && $p) {
    $conn = mysql_connect("localhost", "root", "") or die("can't connect this database");
    mysql_select_db("banhang", $conn);
    $sqladmin = "select * from taikhoan where TenDangNhap='" . $u . "' and MatKhau='" . $p . "' and LoaiTaiKhoan='1'";
    $sqluser = "select * from taikhoan where TenDangNhap='" . $u . "' and MatKhau='" . $p . "' and LoaiTaiKhoan='2'";
    $queryadmin = mysql_query($sqladmin);
    $queryuser = mysql_query($sqluser);
    if (mysql_num_rows($queryadmin) != 0) {
        $row = mysql_fetch_array($queryadmin);
        session_start();
        $_SESSION['userid'] = $row[ID];
        $_SESSION['level'] = $row[LoaiTaiKhoan];
        session_register("thu");
        echo 'Dang nhap thanh cong';
        Header("Location: Admin/TrangChu.php");
    }
    if (mysql_num_rows($queryuser) != 0) {
        $row = mysql_fetch_array($queryuser);
        session_start();
        $_SESSION['userid'] = $row[ID];
        $_SESSION['loai'] = $row[LoaiTaiKhoan];
        Header("Location: TrangChu.php");
    }
    if (mysql_num_rows($queryuser) == 0 || mysql_num_rows($queryadmin) == 0) {
        $err = "Ten dang nhap hoac mat khau khong dung<br />";
    }
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Website Hoang Do</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />	
        <link rel="stylesheet" type="text/css" href="Parts/style.css" media="screen" />        
    </head>
    <body>
        <div id="wrap">
            <div id="header">
                <h1><a href="#">HD Fashion</a></h1>
                <h2>Best Price For You</h2>
            </div>
            <div id="top"> </div>
            <div id="contentt">
                <!--Header menu  --> 
                <?php include 'Parts/HeaderMenu.php'; ?>

                <!--Left menu  -->             
                <div>
                    <?php include 'Parts/Left.php'; ?>
                </div>
                <!--Middle content(tu lam cai nay)  --> 
                <div class="middle">
                    <form action="DangNhap.php" method="post">
                        <h2>Đăng nhập</h2>
                        <table border="0" style="margin-left: 100px;margin-top: 20px">                      
                            <tr>
                                <td>Tên Đăng Nhập</td>
                                <td><input type="text" name="tendangnhap" value="" size="30" /></td>
                            </tr>
                            <tr>
                                <td>Mật Khẩu</td>
                                <td><input type="password" name="matkhau" value="" size="30"  /></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" value="Đăng Nhập" name="dangnhap" style="width: 70px"/><span>  </span><input type="reset" value="Hũy" name="huy" style="width: 70px"/></td>
                            </tr>
                            <tr>
                                <td align="center" style="color: red" colspan="2"> 
                                    <? echo $err; ?>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
                <!-- menu right-->
                <div>
                    <?php include 'Parts/Right.php'; ?>
                </div>
                <div style="clear: both;"> </div>
            </div>
            <div id="bottom"> </div>
            <!-- Footer-->
            <div>
                <?php include 'Parts/Footer.php'; ?>
            </div>
        </div>
    </body>
</html>